<template>
  <view class="register-page">
    <image class="register-icon" src="../../static/shudong.png" />
    <view class="input-container">
      <input type="text" v-model="phoneNumber" placeholder="请输入手机号" style="border: 1px solid #ccc; border-bottom: 2px solid #000;" />
      <input type="password" v-model="password" placeholder="请输入密码" style="border: 1px solid #ccc; border-bottom: 2px solid #000;" />
    </view>
    <button @click="register">注册</button>
  </view>
</template>

<script >
export default {
  data() {
    return {
      phoneNumber: '',
      password: ''
    };
  },
  methods: {
    register() {
      // 对密码进行 SHA256 加密
      // const encryptedPassword = CryptoJS.SHA256(this.password).toString(CryptoJS.enc.Hex);
      uni.request({
        url: 'http://localhost:9090/users/register',  // 替换为实际的注册接口地址
        method: 'POST',
        data: {
          username: 'luo5',
          password: '182389'  // 使用加密后的密码
        },
        success: (res) => {
          if (res.data.success) {
            uni.navigateTo({
              url: '/pages/message/message'
            });
          } else {
            uni.showToast({
              title: '注册失败，请重试',
              icon: 'none'
            });
          }
        },
        fail: (err) => {
          uni.showToast({
            title: '注册请求失败，请稍后重试',
            icon: 'none'
          });
        }
      });
    }
  }
};
</script>

<style>
.register-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.register-icon {
  width: 100px;
  height: 100px;
}

.input-container {
  width: 80%;
  margin-top: 20px;
}

input {
  width: 100%;
  padding: 10px;
}

button {
  width: 80%;
  padding: 10px;
  background-color: #4CAF50;
  color: white;
  border: none;
  cursor: pointer;
  margin-top: 20px;
}
</style>